﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Phone.Scheduler;

namespace WP8ScheduledTaskAgent
{
    public static class PeriodicTasksManager
    {
        public static void ReschedulePeriodicTask(string periodicTaskName, string aDescription)
        {
            var periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
            if (periodicTask != null)
            {
                ScheduledActionService.Remove(periodicTaskName);
            }

            periodicTask = new PeriodicTask(periodicTaskName);
            periodicTask.Description = aDescription;
            ScheduledActionService.Add(periodicTask);
        }

        public static void LaunchAllForTest()
        {
            ScheduledActionService.LaunchForTest("recordingTask", TimeSpan.FromSeconds(60));
            ScheduledActionService.LaunchForTest("playbackManagement", TimeSpan.FromSeconds(60));
        }

        public static void RescheduleAll()
        {
            ReschedulePeriodicTask("recordingTask", "Shows recording");
            ReschedulePeriodicTask("playbackManagement", "Auto Start/Stop");
        }
}
}
